home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / CD Playthrough 1.5.sit / CD Playthrough 1.5 / Source / SoundComponents.h < prev    next >
Text File  |  1994-09-26  |  15KB  |  387 lines

  1. /*
  2.     File:        SoundComponents.h
  3.  
  4.     Contains:    Prototypes for Sound Components
  5.  
  6.     Written by:    Jim Reekes and Kip Olson
  7.  
  8.     Copyright:    ) 1991-1994 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef __SOUNDCOMPONENTS__
  12. #define __SOUNDCOMPONENTS__
  13.  
  14.  
  15. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. // C include files cannot be used by Rez
  17. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  18.  
  19. #ifndef forRez
  20.  
  21.     #include <Components.h>
  22.     #include <Sound.h>
  23.  
  24. #endif
  25.  
  26.  
  27. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. // constants
  29. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30.  
  31. // sound component types and subtypes
  32.  
  33. #define kNoSoundComponentType            '****'
  34.  
  35. #define kSoundComponentType                'sift'
  36. #define     kRate8SubType                'ratb'        /* 8-bit rate converter */
  37. #define     kRate16SubType                'ratw'        /* 16-bit rate converter */
  38. #define        kConverterSubType            'conv'        /* sample format converter */
  39. #define        kSndSourceSubType            'sour'        /* generic source component */
  40.  
  41. #define kMixerType                        'mixr'
  42. #define     kMixer8SubType                'mixb'        /* 8-bit mixer */
  43. #define     kMixer16SubType                'mixw'        /* 16-bit mixer */
  44.  
  45. // these component types must match the gestaltSoundHardware result
  46. #define     kClassicSubType                'clas'        /* "classic" hardware, i.e. Mac + */
  47. #define     kASCSubType                    'asc '        /* Apple Sound Chip device */
  48. #define     kDSPSubType                    'dsp '        /* DSP device */
  49. #define     kAwacsSubType                'awac'        /* Another of Will's Audio Chips device */
  50. #define        kSingerSubType                'sing'        /* Singer (via Whitney) based sound (Blackbird) */
  51.  
  52. #define kSoundCompressor                'scom'
  53. #define kSoundDecompressor                'sdec'
  54. #define     kMace3SubType                'MAC3'        /* MACE 3:1 */
  55. #define     kMace6SubType                'MAC6'        /* MACE 6:1 */
  56. #define     kCDXA4SubType                'CDX4'        /* CD/XA 4:1 */
  57. #define     kCDXA2SubType                'CDX2'        /* CD/XA 2:1 */
  58.  
  59. #define kSoundComponentCodeType            kSoundComponentType    /* code for the sound components */
  60.  
  61. // Audio components and sub-types
  62. #define kAudioComponentType                'adio'
  63. #define kAudioCodeType                    kAudioComponentType
  64. #define kAwacsPhoneSubType                'hphn'
  65. #define kTeleSpeakerSubType                'telc'
  66. #define kTeleHeadphoneSubType            'telh'
  67.  
  68. // sound component set/get info selectors
  69. #define siVolume                        'volu'
  70. #define siHardwareVolume                'hvol'
  71. #define siSpeakerVolume                    'svol'
  72. #define siHeadphoneVolume                'pvol'
  73. #define siHardwareVolumeSteps            'hstp'
  74. #define siHeadphoneVolumeSteps            'hdst'
  75. #define siHardwareMute                    'hmut'
  76. #define siSpeakerMute                    'smut'
  77. #define siHeadphoneMute                    'pmut'
  78. #define siRateMultiplier                'rmul'
  79. #define siQuality                        'qual'
  80.  
  81. // format types
  82. #define kOffsetBinary                    'raw '
  83. #define kTwosComplement                    'twos'
  84. #define kMACE3Compression                'MAC3'
  85. #define kMACE6Compression                'MAC6'
  86.  
  87. // quality flags
  88. #define kBestQuality            (1 << 0)        /* use interpolation in rate conversion */
  89.  
  90. // features flags
  91. #define k8BitRawIn                (1 << 0)        /* data description */
  92. #define k8BitTwosIn                (1 << 1)
  93. #define k16BitIn                (1 << 2)
  94. #define kStereoIn                (1 << 3)
  95. #define k8BitRawOut                (1 << 8)
  96. #define k8BitTwosOut            (1 << 9)
  97. #define k16BitOut                (1 << 10)
  98. #define kStereoOut                (1 << 11)
  99.  
  100. #define kReverse                (1 << 16)        /* function description */
  101. #define kRateConvert            (1 << 17)
  102. #define kCreateSoundSource        (1 << 18)
  103.  
  104. #define kHighQuality            (1 << 22)        /* performance description */
  105. #define kRealTime                (1 << 23)
  106.  
  107. #define kInputMask                0x000000FF        /* masks off input bits */
  108. #define kOutputMask                0x0000FF00        /* masks off output bits */
  109. #define kOutputShift            8                /* amount output bits are shifted */
  110. #define kActionMask                0x00FF0000        /* masks off action bits */
  111. #define kSoundComponentBits        0x00FFFFFF
  112.  
  113.  
  114. // SoundComponentPlaySourceBuffer action flags
  115. #define kSourcePaused            (1 << 0)
  116.  
  117. #define kPassThrough            (1 << 16)
  118. #define kNoSoundComponentChain    (1 << 17)
  119.  
  120. // flags for OpenMixerSoundComponent
  121. #define kNoMixing                (1 << 0)        /* don't mix source */
  122. #define kNoSampleRateConversion    (1 << 1)        /* don't convert sample rate (i.e. 11 kHz -> 22 kHz) */
  123. #define kNoSampleSizeConversion    (1 << 2)        /* don't convert sample size (i.e. 16 -> 8) */
  124. #define kNoSampleFormatConversion (1 << 3)        /* don't convert sample format (i.e. 'twos' -> 'raw ') */
  125. #define kNoChannelConversion    (1 << 4)        /* don't convert stereo/mono */
  126. #define kNoDecompression        (1 << 5)        /* don't decompress (i.e. 'MAC3' -> 'raw ') */
  127. #define kNoVolumeConversion        (1 << 6)        /* don't apply volume */
  128. #define kNoRealtimeProcessing    (1 << 7)        /* won't run at interrupt time */
  129.  
  130.  
  131. // Audio Component constants
  132.  
  133. // Values for whichChannel parameter
  134. #define audioAllChannels        0                /* All channels (usually interpreted as both left and right) */
  135. #define audioLeftChannel         1                /* Left channel */
  136. #define audioRightChannel        2                /* Right channel */
  137.  
  138. // Values for mute parameter
  139. #define audioUnmuted            0                /* Device is unmuted */
  140. #define audioMuted                1                /* Device is muted */
  141.  
  142. // Capabilities flags definitions
  143. #define audioDoesMono            (1L<<0)            /* Device supports mono output */
  144. #define audioDoesStereo            (1L<<1)            /* Device supports stereo output */
  145. #define audioDoesIndependentChannels (1L<<2)    /* Device supports independent software control of each channel */
  146.  
  147.  
  148. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. // typedefs
  150. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151.  
  152. // typedefs cannot be used by Rez
  153. #ifndef forRez
  154.  
  155. // This type consists of an 8 bit, 2's complement integer part in the high byte,
  156. // with an 8 bit fractional part in the low byte; its range is -128 to 127.99609375
  157. typedef short ShortFixed;
  158.  
  159. typedef struct SoundComponentData SoundComponentData;
  160. typedef struct SoundComponentData *SoundComponentDataPtr;
  161.  
  162. struct SoundComponentData {
  163.     long            flags;
  164.     OSType            format;
  165.     short            numChannels;
  166.     short            sampleSize;
  167.     UnsignedFixed    sampleRate;
  168.     long            sampleCount;
  169.     Byte            *buffer;
  170.     long            reserved;
  171. };
  172.  
  173. typedef struct SoundParamBlock SoundParamBlock;
  174. typedef SoundParamBlock *SoundParamBlockPtr;
  175.  
  176. typedef pascal Boolean (*SoundParamProcPtr)(SoundParamBlockPtr *pb);
  177.  
  178. struct SoundParamBlock {
  179.     long                recordSize;                // size of this record in bytes
  180.     SoundComponentData    desc;                    // description of sound buffer
  181.     Fixed                rateMultiplier;            // rate multiplier to apply to sound
  182.     short                leftVolume;                // volumes to apply to sound
  183.     short                rightVolume;
  184.     long                quality;                // quality to apply to sound
  185.     ComponentInstance    filter;                    // filter to apply to sound
  186.     SoundParamProcPtr    moreRtn;                // routine to call to get more data
  187.     SoundParamProcPtr    completionRtn;            // routine to call when buffer is complete
  188.     long                refCon;                    // user refcon
  189.     short                result;                    // result
  190. };
  191.  
  192. // private thing to use as a reference to a chain
  193. typedef struct privateSoundSource *SoundSource;
  194.  
  195. typedef struct CompressionInfo CompressionInfo;
  196. typedef CompressionInfo *CompressionInfoPtr;
  197. typedef CompressionInfoPtr *CompressionInfoHandle;
  198.  
  199. struct CompressionInfo {
  200.     long        recordSize;
  201.     OSType        format;
  202.     short        compressionID;
  203.     short        samplesPerPacket;
  204.     short        bytesPerPacket;
  205.     short        bytesPerFrame;
  206.     short        bytesPerSample;
  207.     short        futureUse1;
  208. };
  209.  
  210. typedef struct AudioInfo AudioInfo;
  211. typedef AudioInfo *AudioInfoPtr;
  212.  
  213. struct AudioInfo {
  214.     long            capabilitiesFlags;            // Describes device capabilities
  215.     long            reserved;                    // Reserved by Apple
  216.     unsigned short    numVolumeSteps;                // Number of significant increments between min and max volume
  217. };
  218.  
  219.  
  220. #endif
  221.  
  222.  
  223. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  224. // functions for sound components
  225. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226.  
  227. // routines cannot be used by Rez
  228. #ifndef forRez
  229.  
  230. #define kDelegatedSoundComponentSelectors    0x0100    /* first selector that can be delegated up the chain*/
  231.  
  232. // Sound Component dispatch selectors
  233. enum {
  234.     kSoundComponentInitOutputDeviceSelect = 1,        /* these calls cannot be delegated */
  235.     kSoundComponentSetSourceSelect,
  236.     kSoundComponentGetSourceSelect,
  237.     kSoundComponentGetSourceDataSelect,
  238.     kSoundComponentSetOutputSelect,
  239.                                                     /* these calls can be delegated */
  240.     kSoundComponentAddSourceSelect = kDelegatedSoundComponentSelectors + 1,
  241.     kSoundComponentRemoveSourceSelect,
  242.  
  243.     kSoundComponentGetInfoSelect,
  244.     kSoundComponentSetInfoSelect,
  245.  
  246.     kSoundComponentStartSourceSelect,
  247.     kSoundComponentStopSourceSelect,
  248.     kSoundComponentPauseSourceSelect,
  249.     kSoundComponentPlaySourceBufferSelect
  250. };
  251.  
  252. // Audio Component selectors
  253. enum {
  254.     kAudioGetVolumeSelect = 0,
  255.     kAudioSetVolumeSelect,
  256.     kAudioGetMuteSelect,
  257.     kAudioSetMuteSelect,
  258.     kAudioSetToDefaultsSelect,
  259.     kAudioGetInfoSelect,
  260.     kAudioMuteOnEventSelect = 129
  261. };
  262.  
  263. #ifdef __cplusplus
  264. extern "C" {
  265. #endif
  266.  
  267. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  268. // Sound Manager 3.0 utilities
  269.  
  270. pascal OSErr OpenMixerSoundComponent(SoundComponentDataPtr outputDescription, long outputFlags, ComponentInstance *mixerComponent)
  271.  = {0x203C,0x0614,0x0018,0xA800};
  272.  
  273. pascal OSErr CloseMixerSoundComponent(ComponentInstance ci)
  274.  = {0x203C,0x0218,0x0018,0xA800};
  275.  
  276.  
  277. #ifndef __cplusplus
  278. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. // basic sound component functions
  280.  
  281. pascal ComponentResult SoundComponentInitOutputDevice(ComponentInstance ti, long actions)
  282.  = ComponentCallNow(kSoundComponentInitOutputDeviceSelect, sizeof(long));
  283.  
  284. pascal ComponentResult SoundComponentSetSource(ComponentInstance ti, SoundSource sourceID, ComponentInstance source)
  285.  = ComponentCallNow(kSoundComponentSetSourceSelect, sizeof(SoundSource) + sizeof(ComponentInstance));
  286.  
  287. pascal ComponentResult SoundComponentGetSource(ComponentInstance ti, SoundSource sourceID, ComponentInstance *source)
  288.  = ComponentCallNow(kSoundComponentGetSourceSelect, sizeof(SoundSource) + sizeof(ComponentInstance));
  289.  
  290. pascal ComponentResult SoundComponentGetSourceData(ComponentInstance ti, SoundComponentDataPtr *sourceData)
  291.  = ComponentCallNow(kSoundComponentGetSourceDataSelect, sizeof(SoundComponentDataPtr));
  292.  
  293. pascal ComponentResult SoundComponentSetOutput(ComponentInstance ti, SoundComponentDataPtr requested, SoundComponentDataPtr *actual)
  294.  = ComponentCallNow(kSoundComponentSetOutputSelect, sizeof(SoundComponentDataPtr) + sizeof(SoundComponentDataPtr));
  295.  
  296.  
  297. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  298. // junction methods for the mixer, must be called at non-interrupt level
  299.  
  300. pascal ComponentResult SoundComponentAddSource(ComponentInstance ti, SoundSource *sourceID)
  301.  = ComponentCallNow(kSoundComponentAddSourceSelect, sizeof(SoundSource));
  302.  
  303. pascal ComponentResult SoundComponentRemoveSource(ComponentInstance ti, SoundSource sourceID)
  304.  = ComponentCallNow(kSoundComponentRemoveSourceSelect, sizeof(SoundSource));
  305.  
  306.  
  307. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  308. // info methods
  309.  
  310. pascal ComponentResult SoundComponentGetInfo(ComponentInstance ti, SoundSource sourceID, OSType selector, void *infoPtr)
  311.  = ComponentCallNow(kSoundComponentGetInfoSelect, sizeof(SoundSource) + sizeof(OSType) + sizeof(Ptr));
  312.  
  313. pascal ComponentResult SoundComponentSetInfo(ComponentInstance ti, SoundSource sourceID, OSType selector, void *infoPtr)
  314.  = ComponentCallNow(kSoundComponentSetInfoSelect, sizeof(SoundSource) + sizeof(OSType) + sizeof(Ptr));
  315.  
  316.  
  317. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  318. // control methods
  319.  
  320. pascal ComponentResult SoundComponentStartSource(ComponentInstance ti, short count, SoundSource *sources)
  321.  = ComponentCallNow(kSoundComponentStartSourceSelect, sizeof(short) + sizeof(SoundSource));
  322.  
  323. pascal ComponentResult SoundComponentStopSource(ComponentInstance ti, short count, SoundSource *sources)
  324.  = ComponentCallNow(kSoundComponentStopSourceSelect, sizeof(short) + sizeof(SoundSource));
  325.  
  326. pascal ComponentResult SoundComponentPauseSource(ComponentInstance ti, short count, SoundSource *sources)
  327.  = ComponentCallNow(kSoundComponentPauseSourceSelect, sizeof(short) + sizeof(SoundSource));
  328.  
  329. pascal ComponentResult SoundComponentPlaySourceBuffer(ComponentInstance ti, SoundSource sourceID,
  330.                                         SoundParamBlockPtr pb, long actions)
  331.  = ComponentCallNow(kSoundComponentPlaySourceBufferSelect, sizeof(SoundSource)
  332.                      + sizeof(SoundParamBlockPtr) + sizeof(long));
  333.  
  334.  
  335. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  336. // interface for Audio Components
  337. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  338.  
  339. // Volume is described as a value between 0 and 1, with 0 indicating minimum
  340. // volume and 1 indicating maximum volume; if the device doesn't support
  341. // software control of volume, then a value of unimpErr is returned, indicating
  342. // that these functions are not supported by the device
  343. pascal ComponentResult AudioGetVolume(ComponentInstance ac, short whichChannel, ShortFixed *volume)
  344.  = ComponentCallNow(kAudioGetVolumeSelect, sizeof(short) + sizeof(Ptr));
  345.  
  346. pascal ComponentResult AudioSetVolume(ComponentInstance ac, short whichChannel, ShortFixed volume)
  347.  = ComponentCallNow(kAudioSetVolumeSelect, sizeof(short) + sizeof(ShortFixed));
  348.  
  349. // If the device doesn't support software control of mute, then a value of
  350. // unimpErr is returned, indicating that these functions are not supported
  351. // by the device
  352. pascal ComponentResult AudioGetMute(ComponentInstance ac, short whichChannel, short *mute)
  353.  = ComponentCallNow(kAudioGetMuteSelect, sizeof(short) + sizeof(Ptr));
  354.  
  355. pascal ComponentResult AudioSetMute(ComponentInstance ac, short whichChannel, short mute)
  356.  = ComponentCallNow(kAudioSetMuteSelect, sizeof(short) + sizeof(short));
  357.  
  358. // AudioSetToDefaults causes the associated device to reset its volume
  359. // and mute values (and perhaps other private characteristics, e.g.
  360. // attenuation) to "factory default" settings
  361. pascal ComponentResult AudioSetToDefaults(ComponentInstance ac)
  362.     = ComponentCallNow(kAudioSetToDefaultsSelect, 0);
  363.  
  364. // This routine is required; it must be implemented by all audio components
  365. pascal ComponentResult AudioGetInfo(ComponentInstance ac, AudioInfoPtr info)
  366.  = ComponentCallNow(kAudioGetInfoSelect, sizeof(AudioInfoPtr));
  367.  
  368.  
  369. // I found this original without the ComponentResult defined as the function's result (?)
  370.  
  371. // This is routine is private to the AudioVision component.  It enables
  372. // the watching of the mute key.
  373. pascal ComponentResult AudioMuteOnEvent(ComponentInstance ac, short muteOnEvent)
  374.  = ComponentCallNow(kAudioMuteOnEventSelect, sizeof(short));
  375. #endif
  376.  
  377. #ifdef __cplusplus
  378. }
  379. #endif
  380.  
  381.  
  382. // if not for Rez
  383. #endif
  384.  
  385. // if already included
  386. #endif
  387.